package com.test.prolenders.view_prolenders.process_widget_prolenders;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.test.prolenders.R;
import com.test.prolenders.base_prolenders.BaseProcessWidgetManager_prolenders;
import com.test.prolenders.bean_prolenders.process_prolenders.ProcessInfo_Data_prolenders;
import com.test.prolenders.dialog_prolenders.DatePickerDialog_prolenders;
import com.test.prolenders.util_prolenders.http_prolenders.HttpUtil_prolenders;


public class DateSelectViewManager_prolenders extends BaseProcessWidgetManager_prolenders {

    private TextView titleTv;
    private TextView inputTv;

    public DateSelectViewManager_prolenders(View view, ProcessInfo_Data_prolenders data, String page){
        super(view,data,page);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void init(){

        titleTv = mView.findViewById(R.id.vpds_tv_title);
        inputTv = mView.findViewById(R.id.vpds_tv_input);

        setTitle(mData.getTitle());
        inputTv.setHint(mData.getHint());

        mView.findViewById(R.id.vpds_view_click).setOnClickListener(v -> {

            HttpUtil_prolenders.getInstance().saveBuriedPoint(page,mData.getParamName().toUpperCase()+"_CLICK","");

            new DatePickerDialog_prolenders(
                    mView.getContext(),
                    mData.getTitle(),
                    date -> {
                        inputTv.setText(date);
                        HttpUtil_prolenders.getInstance().saveBuriedPoint(page,mData.getParamName().toUpperCase()+"_CLICK",getInput());
                    }
            ).show();
        });

    }

    @Override
    public boolean checkInput() {
        if (!mData.isMustInput()) return true;
        return !TextUtils.isEmpty(inputTv.getText());
    }

    @Override
    public String getInput() {
        return inputTv.getText().toString();
    }

    public void setTitle(String title){
        if (TextUtils.isEmpty(title)) titleTv.setVisibility(View.GONE);
        else {
            titleTv.setVisibility(View.VISIBLE);
            titleTv.setText(title);
        }
    }

}
